<template>
  <div class="transfer">
    <div class="center" v-for="item in cardLists" :key="item.id">
      <div class="title">SHA</div>
      <van-collapse
        v-model="activeNames"
        v-for="(citem, cindex) in item.children"
        :key="citem.id"
        style="margin-top: 20px"
      >
        <van-collapse-item :title="citem.name" :name="cindex">
          <van-button
            type="default"
            size="small"
            v-for="bitem in citem.children"
            :key="bitem.id"
            style="margin: 2px 5px"
            @click="clickEven(bitem)"
            >{{ bitem.name }}</van-button
          >
        </van-collapse-item>
      </van-collapse>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { Collapse, CollapseItem, Button } from "vant";
export default {
  data() {
    return {
      activeNames: [0, 1, 2],
      cardLists: [],
    };
  },
  components: {
    [Collapse.name]: Collapse,
    [CollapseItem.name]: CollapseItem,
    [Button.name]: Button,
  },
  mounted() {
    this.getDepartments();
    this.$emit("currentPath", "/transfer");
  },
  destroyed() {
    this.$emit("currentPath", "");
  },
  methods: {
    async getDepartments() {
      const res = await axios.post("SicCore/GetProcess", {
        userId: JSON.parse(sessionStorage.getItem("userInfo")).userName,
        IsHome: true,
      });

      if (res.length == 0) {
        // if (isAdmin) {
        //   clickEven(
        //     {
        //       id: "",
        //       description: "",
        //       name: "SIC",
        //       children: [],
        //     },
        //     {
        //       id: "",
        //       description: "",
        //       name: "sic",
        //       children: [],
        //     }
        //   );
        // }
      }

      if (res.length === 1 && res[0].children.length === 1) {
        clickEven(res[0].children[0].children[0]);
      }

      this.cardLists = res;
    },
    clickEven(item) {
      console.log(item);
      this.$router.push({
        path: "/",
      });
      sessionStorage.setItem("currentDepartment", JSON.stringify(item));
    },
  },
};
</script>

<style scoped>
.center {
  width: 85%;
  margin: 20px auto 42px;
  padding: 20px;
  border-radius: 15px;
  box-shadow: rgb(136 165 191 / 48%) 6px 2px 16px 0,
    rgb(255 255 255 / 80%) -6px -2px 16px 0;
  background-color: #fff;
}
.van-collapse-item /deep/ .van-cell {
  background-color: rgb(247, 247, 247);
}
.van-collapse-item /deep/ .van-collapse-item__content {
  background-color: rgb(247, 247, 247);
}
</style>
